<template>
  <div>
    <!-- 头部 -->
    <header class="header">
      <router-link tag="div" to="/index" class="left"></router-link>
      <div class="title">个人中心</div>
    </header>

    <header class="wrap" v-if="userInfo">
      <div class="content">
        <div class="user">
          <img :src="userInfo.userImg" alt="" />
        </div>
        <div class="text">
          <div class="name">{{ userInfo.username }}</div>
          <div class="balance">
            书豆 <span>{{ userInfo.balance }}</span>
          </div>
        </div>
      </div>
    </header>
    <!-- 头部 -->

    <!-- 功能列表 -->
    <div class="user_list wrap">
      <!-- 会员开通界面 -->
      <router-link to="/vip" class="item">
        <div class="left">我的会员</div>
        <div class="right">
          <span>开通会员</span>
          <i class="icon-arrow-right-bold iconfont"></i>
        </div>
      </router-link>

      <!-- 书豆 -->
      <router-link to="/recharge" class="item">
        <div class="left">书豆</div>
        <div class="right">
          <span>充值</span>
          <i class="icon-arrow-right-bold iconfont"></i>
        </div>
      </router-link>

      <!-- 充值消费记录 -->
      <!-- <a class="item">
        <div class="left">消费充值记录</div>
        <div class="right">
          <span></span>
          <i class="icon-arrow-right-bold iconfont"></i>
        </div>
      </a> -->

      <!-- 购买过的书 -->
      <router-link tag="div" to="/bookShelf" class="item">
        <div class="left">我的收藏</div>
        <div class="right">
          <span></span>
          <i class="icon-arrow-right-bold iconfont"></i>
        </div>
      </router-link>

      <!-- 意见反馈 -->
      <a class="item">
        <div class="left">意见反馈</div>
        <div class="right">
          <span></span>
          <i class="icon-arrow-right-bold iconfont"></i>
        </div>
      </a>
    </div>
    <!-- 功能列表 -->

    <!-- 退出登录功能 -->
    <div class="log_out" @click="log_out">退出</div>
    <!-- 退出登录功能 -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      lists: [],
      userInfo: null,
    };
  },
  methods: {
    getUserDataFun() {
      let userId = localStorage.getItem("userId");
      this.userInfo = JSON.parse(localStorage.getItem("userInfo"))[userId];
    },
    log_out() {
      localStorage.setItem("userId", "");
      this.$router.push("/Login");
    },
  },
  created() {
    this.getUserDataFun();
  },
};
</script>

<style lang="scss" scoped>
header {
  padding: 12px 16px 16px;
  box-sizing: border-box;
  width: 100%;

  > .content {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    box-shadow: 0 4px 12px 0 rgb(0 0 0 / 10%);

    > .user {
      width: 60px;
      height: 60px;
      margin: 32px 16px;
      border-radius: 50%;
      overflow: hidden;

      > img {
        width: 100%;
        height: 100%;
      }
    }

    > .text {
      color: #333;
      font-size: 18px;
      font-weight: bold;
      flex: 1;

      > .balance {
        margin-top: 10px;
        font-size: 13px;
        color: #999;
        font-weight: 100;

        > span {
          color: #23b383;
          font-weight: bold;
        }
      }
    }
  }
}

header.header {
  height: 50px;
  text-align: center;
  border-bottom: 2px solid #f0f0f0;
  position: relative;
  padding: 0;

  > .left {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 15px;
    margin: auto;
    transform: rotate(180deg);
    background: url(https://easyreadfs.nosdn.127.net/web/trunk/1533607652166/icon_return.png)
      no-repeat;
    background-size: contain;
    width: 12px;
    height: 20px;
  }

  > .title {
    color: #333;
    font-weight: bold;
    line-height: 50px;
    font-size: 18px;
  }
}

.user_list {
  > .item {
    display: block;
    width: 100%;
    line-height: 21px;
    padding: 21px 16px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    color: #333;
    font-size: 16px;
    position: relative;

    > .right {
      display: flex;
      align-items: center;

      > span {
        color: #999;
        font-size: 14px;
        margin-right: 5px;
      }

      > i.iconfont {
        font-size: 16px;
        color: #999;
      }
    }

    &::after {
      content: "";
      position: absolute;
      height: 1px;
      left: 16px;
      right: 16px;
      bottom: 0;
      background: #eee;
      transform: scaleY(0.5);
    }
  }
}

.log_out {
  height: 65px;
  line-height: 65px;
  font-size: 16px;
  text-align: center;
}
</style>